package net.da.tools;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BodyBlock extends BodyElement {

	private static final String EMPTY_STRING = "";

	private List<BodyElement> elements;

	private String header;

	public BodyBlock() {
		elements = new ArrayList<BodyElement>();
		header = EMPTY_STRING;
	}

	public void addElement(BodyElement element) {
		elements.add(element);
	}

	public List<BodyElement> getElements() {
		return Collections.unmodifiableList(elements);
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public List<ClassDescriptor> getAllUsages() {

		List<ClassDescriptor> all = new ArrayList<ClassDescriptor>();
		all.addAll(getUsages());
		for (BodyElement element : elements) {
			if (element instanceof BodyBlock) {
				all.addAll(((BodyBlock) element).getAllUsages());
			} else {
				all.addAll(element.getUsages());
			}
		}
		return Collections.unmodifiableList(all);
	}

}
